package cn.sirun.com.fca.account.activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;


import com.tencent.cloud.iov.util.BitmapUtils;
import com.tencent.cloud.uikit.ui.BaseIovActivity;

import cn.sirun.com.fca.account.constant.AccountCommonConst;
import cn.sirun.com.fca.account.uitl.HandleBackUtils;
import cn.sirun.com.fca.account.view.impl.AuthenticationFlowView;

/**
 * @author vinsonhuang
 * @date 2018/5/4
 */
public class AuthenticationActivity extends BaseIovActivity {

    private static final String TAG = AuthenticationActivity.class.getSimpleName();

    private AuthenticationFlowView mAuthenticationFlowView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mAuthenticationFlowView = new AuthenticationFlowView(this);
        getLifecycle().addObserver(mAuthenticationFlowView);
    }

    @Override
    protected boolean isActionBarOverlay() {
        return true;
    }

    @Override
    protected boolean isStatusBarOverlay() {
        return true;
    }

    @Override
    public void onBackPressed() {
        if (!HandleBackUtils.handleBackPress(this)) {
            super.onBackPressed();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (AccountCommonConst.PHOTO_FROM_ALBUM_REQUEST_CODE == requestCode) {
            if (Activity.RESULT_OK == resultCode) {
                Uri uri = data.getData();
                String filePath = BitmapUtils.getRealPathFromUri(this, uri);
                mAuthenticationFlowView.setAuthImage(filePath);
            }
        } else if (AccountCommonConst.TURN_TO_VEHICLE_MANAGEMENT_RESULT_CODE == resultCode) {
            finish();
        }
    }
}
